<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.ibm.dao.UserMapper">
	<resultMap type="cn.ibm.User" autoMapping="true" id="user">
		<id column="id" property="id" />
		<result column="name" property="name" />
	</resultMap>
	<parameterMap id="paramMap" type="cn.ibm.User">
		<parameter property="id" resultMap="id" />
		<parameter property="name" resultMap="name" />
	</parameterMap>
	<sql id="where_sql">
		<if test="id!=null">
			id=#{id}
		</if>
		<if test="name!=null">
			name=#{name}
		</if>
		<if test="pageStart != null && pageEnd !=null">
			limit ${pageStart}, ${pageEnd}
		</if>
	</sql>

	<sql id="param">
		id,name
	</sql>
	<!-- public T getById(Serializable id); -->
	<select id="getById" resultMap="user">
		select * from User where id =
		#{id}
	</select>

	<!-- public void save(final T t); -->
	<insert id="save" parameterType="cn.ibm.User">
		insert into User
		(name) values
		(#{name});
	</insert>

	<!-- public void saveOrUpdate(final T t); -->

	<!-- public void remove(final T t); -->
	<delete id="remove" parameterType="cn.ibm.User">
		delete from user
		<where>
			<include refid="where_sql" />
		</where>
	</delete>

	<!-- public List<T> getAll(); -->
	<select id="getAll" resultMap="user">
		select
		<include refid="param" />
		from User
	</select>
	<!-- public int count(final T t); -->
	<select id="count" parameterType="cn.ibm.User" resultType="Integer">
		select count(*) from User
		<where>
			<include refid="where_sql" />
		</where>
	</select>
</mapper>